package grasil.org.prototyp;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Peter on 9. 8. 2014.
 */
public class CustomAdapter extends BaseAdapter {

    List<RowItem> rowItems;
    private LayoutInflater layoutInflater;

    CustomAdapter(Context context, List<RowItem> rowItem) {
        this.layoutInflater= LayoutInflater.from(context);
        this.rowItems = rowItem;
    }

    @Override
    public int getCount() {
        return rowItems.size();
    }

    @Override
    public Object getItem(int position) {
        return rowItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return  position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView==null){
            convertView = layoutInflater.inflate(R.layout.list_tem, null);
            viewHolder=new ViewHolder();
            viewHolder.title= (TextView) convertView.findViewById(R.id.textView);
            viewHolder.icon= (ImageView) convertView.findViewById(R.id.imageView);
            convertView.setTag(viewHolder);
        }else{
            viewHolder= (ViewHolder) convertView.getTag();
        }
        viewHolder.title.setText(rowItems.get(position).getTitle());
        viewHolder.icon.setImageResource(rowItems.get(position).getIcon());
        return  convertView;
    }

    class ViewHolder{
        TextView title;
        ImageView icon;
    }
}
